unit UContasPagarCt;

interface

uses UContasPagarMd, UContasPagarDb, Classes, DB, SysUtils, URequestContasPagar;

type
   TContasPagarCt = class(TObject)

      private
         aObjContasPagarMd : TContasPagarMd;
         aObjContasPagarDb : TContasPagarDb;

      public
         constructor Create;
         destructor Destroy;

         function inserirValorContasPagar(req : TRequestContasPagar) : Boolean;
         function inserirContasPagar : Boolean;
         function alterarContasPagar : Boolean;
         function excluirContasPagar(req : TRequestContasPagar) : Boolean;
         function procurarContasPagar(req : TRequestContasPagar) : Boolean;
         function pagarContasPagar(req : TRequestContasPagar) : Boolean;         
         function obterContasPagar : TContasPagarMd;
         function obterListaContasPagar(Param : String) : TList; Overload;
         function obterListaContasPagar : TDataSet; Overload;
end;

implementation

constructor TContasPagarCt.Create;
begin
  inherited;
    self.aObjContasPagarMd := TContasPagarMd.Create;
    self.aObjContasPagarDb := TContasPagarDb.Create;
end;

destructor TContasPagarCt.Destroy;
begin
    self.aObjContasPagarMd.Destroy;
    self.aObjContasPagarDb.Destroy;
  inherited;
end;

function TContasPagarCt.inserirValorContasPagar(req : TRequestContasPagar) : Boolean;
begin
  if (req.acao = 'inserir') then
    self.aObjContasPagarMd.setIdContasPagar(
      self.aObjContasPagarDb.obterObjPersistenciaSQL.obterCodigo('pagar'))
  else
    self.aObjContasPagarMd.setIdContasPagar(req.id_contaspagar);
  self.aObjContasPagarMd.setDataPagamento(req.data_pagamento);
  self.aObjContasPagarMd.setValor(req.valor);
  self.aObjContasPagarMd.setObservacao(req.observacoes);

  result := true;
end;

function TContasPagarCt.inserirContasPagar : Boolean;
var
  retorno : Boolean;
begin
  retorno := false;
  if (self.aObjContasPagarDb.inserirContasPagar(self.aObjContasPagarMd)) then
    retorno := true;
  result := retorno;
end;

function TContasPagarCt.alterarContasPagar : Boolean;
begin
  if (self.aObjContasPagarMd <> nil) then
    self.aObjContasPagarDb.alterarContasPagar(self.aObjContasPagarMd);
end;

function TContasPagarCt.excluirContasPagar(req : TRequestContasPagar) : Boolean;
begin
  self.aObjContasPagarDb.excluirContasPagar(req.id_contaspagar);
end;

function TContasPagarCt.procurarContasPagar(req : TRequestContasPagar) : Boolean;
begin
  if ((IntToStr(req.id_contaspagar) <> '') and (req.id_contaspagar = 0)) then
    self.aObjContasPagarMd := self.aObjContasPagarDb.procurarContasPagar(
      req.id_contaspagar);
end;

function TContasPagarCt.obterContasPagar : TContasPagarMd;
begin
end;

function TContasPagarCt.obterListaContasPagar : TDataSet;
begin
   try
      result := self.aObjContasPagarDb.obterListaContasPagar;
   except
      on e : Exception do
   end;
end;

function TContasPagarCt.obterListaContasPagar(Param : String) : TList;
begin
end;

function TContasPagarCt.pagarContasPagar(req : TRequestContasPagar) : Boolean;
begin
  if ((IntToStr(req.id_contaspagar) <> '') and (req.id_contaspagar <> 0)) then
    self.aObjContasPagarDb.pagarContasPagar(req.id_contaspagar);
end;

end.
 